package com.mojawa.mj_amap.location

import com.amap.api.maps.AMapUtils
import com.amap.api.maps.model.LatLng
import com.mojawa.mj_amap.bean.PathRecord

class MJRunAmapUtil {
    private var distance: Double = 0.00
    private val record: PathRecord? = null

    companion object {
        /**
         * 计算距离
         * @JvmStatic在kotlin指静态
         */
        @JvmStatic
        fun getDistance(list: List<LatLng>?): Float {
            var distance = 0.0f
            if (list.isNullOrEmpty()) {
                return distance
            }
            for (i in 0 until list.size - 1) {
                val firstLatLng = list[i]
                val secondLatLng = list[i + 1]
                val betweenDis = AMapUtils.calculateLineDistance(firstLatLng, secondLatLng)
                distance += betweenDis.toFloat()
            }

            return distance
        }


    }

    fun getDistance() {
        distance = record?.pathLinePoints?.let { getDistance(it).toDouble() } ?: 0.0
    }
}